package data

import (
	"devops/models"
	"devops/pkg/jenkins/api_type"
)

type TestResult struct {
	Duration  float64 `json:"duration"` // 总计耗时 毫秒
	Empty     bool    `json:"empty"`
	FailCount int64   `json:"failCount"` // 失败个数
	PassCount int64   `json:"passCount"` // 成功个数
	SkipCount int64   `json:"skipCount"` // 跳过个数
	Suites    []struct {
		Cases []struct {
			Age             int64       `json:"age"`
			ClassName       string      `json:"className"`
			Duration        float64     `json:"duration"`
			ErrorDetails    interface{} `json:"errorDetails"`
			ErrorStackTrace interface{} `json:"errorStackTrace"` // 失败日志
			FailedSince     int64       `json:"failedSince"`
			Name            string      `json:"name"` // 标题
			Skipped         bool        `json:"skipped"`
			SkippedMessage  interface{} `json:"skippedMessage"`
			Status          string      `json:"status"`
			Stderr          interface{} `json:"stderr"`
			Stdout          interface{} `json:"stdout"`
		} `json:"cases"`
		Duration  float64     `json:"duration"`
		ID        interface{} `json:"id"`
		Name      string      `json:"name"`
		Stderr    interface{} `json:"stderr"`
		Stdout    interface{} `json:"stdout"`
		Timestamp interface{} `json:"timestamp"`
	} `json:"suites"`
}

type GetBuildAllResponse struct {
	PageResponse
	Data []models.Build
}

type SuccessGetBuildAll struct {
	Code int           `json:"code" example:"200"`     // 业务响应状态码
	Msg  string        `json:"message" example:"请求成功"` // 提示信息
	Data GetCIResponse `json:"data" example:""`        // 返回说明文字
}

type SuccessGetBuild struct {
	Code int                     `json:"code" example:"200"`     // 业务响应状态码
	Msg  string                  `json:"message" example:"请求成功"` // 提示信息
	Data models.BuildOneResponse `json:"data"`                   // 返回说明文字
}

type FailGetBuild struct {
	Code int    `json:"code" example:"12000"`        // 业务响应状态码
	Msg  string `json:"message" example:"build 未找到"` // 提示信息
	Data string `json:"data" example:""`             // 返回说明文字
}

type SuccessGetStageLog struct {
	Code int                   `json:"code" example:"200"`     // 业务响应状态码
	Msg  string                `json:"message" example:"请求成功"` // 提示信息
	Data models.BuildStageInfo `json:"data"`                   // 返回说明文字
}

type SuccessGetTestReport struct {
	Code int        `json:"code" example:"200"`     // 业务响应状态码
	Msg  string     `json:"message" example:"请求成功"` // 提示信息
	Data TestResult `json:"data"`                   // 返回说明文字
}

type SuccessGetArtifacts struct {
	Code int                    `json:"code" example:"200"`     // 业务响应状态码
	Msg  string                 `json:"message" example:"请求成功"` // 提示信息
	Data []models.BuildArtifact `json:"data"`                   // 返回说明文字
}

type FailDownload struct {
	Code int    `json:"code" example:"404"`      // 业务响应状态码
	Msg  string `json:"message" example:"文件未找到"` // 提示信息
	Data string `json:"data"`                    // 返回说明文字
}

type SuccessRun struct {
	Code int          `json:"code" example:"200"`     // 业务响应状态码
	Msg  string       `json:"message" example:"请求成功"` // 提示信息
	Data models.Build `json:"data"`                   // 返回说明文字
}

type FailRun struct {
	Code int    `json:"code" example:"12001"`     // 业务响应状态码
	Msg  string `json:"message" example:"启动构建失败"` // 提示信息
	Data string `json:"data"`                     // 返回说明文字
}

type SuccessDeleteBuild struct {
	Code int    `json:"code" example:"200"`     // 业务响应状态码
	Msg  string `json:"message" example:"请求成功"` // 提示信息
	Data string `json:"data" example:"删除成功"`    // 返回说明文字
}
type FailDeleteBuild struct {
	Code int    `json:"code" example:"11001"`     // 业务响应状态码
	Msg  string `json:"message" example:"启动构建失败"` // 提示信息
	Data string `json:"data"`                     // 返回说明文字
}

type SuccessGetBuildConsoleOutput struct {
	Code int    `json:"code" example:"200"`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   // 业务响应状态码
	Msg  string `json:"message" example:"请求成功"`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               // 提示信息
	Data string `json:"data" example:"Started by user gaffey\nRunning in Durability level: MAX_SURVIVABILITY\n[Pipeline] Start of Pipeline\n[Pipeline] node\nRunning on Jenkins in /var/jenkins_home/workspace/安畅devops/coding-example\n[Pipeline] {\n[Pipeline] stage\n[Pipeline] { (检出)\n[Pipeline] checkout\nSelected Git installation does not exist. Using Default\nThe recommended git tool is: NONE\nNo credentials specified\n > git rev-parse --resolve-git-dir /var/jenkins_home/workspace/安畅devops/coding-example/.git # timeout=10\nFetching changes from the remote Git repository\n > git config remote.origin.url https://gitee.com/gaffeyqiu/building-a-multibranch-pipeline-project1 # timeout=10\nFetching upstream changes from https://gitee.com/gaffeyqiu/building-a-multibranch-pipeline-project1\n > git --version # timeout=10\n > git --version # 'git version 2.26.3'\n > git fetch --tags --force --progress -- https://gitee.com/gaffeyqiu/building-a-multibranch-pipeline-project1 +refs/heads/*:refs/remotes/origin/* # timeout=10\n > git rev-parse origin/master^{commit} # timeout=10\nChecking out Revision 1a10a83a9f814bb65deb502d9603163db158a87e (origin/master)\n > git config core.sparsecheckout # timeout=10\n > git checkout -f 1a10a83a9f814bb65deb502d9603163db158a87e # timeout=10\nCommit message: \"update Jenkinsfile.\"\n > git rev-list --no-walk 1a10a83a9f814bb65deb502d9603163db158a87e # timeout=10\n[Pipeline] }\n[Pipeline] // stage\n[Pipeline] stage\n[Pipeline] { (构建)\n[Pipeline] echo\n构建中...\n[Pipeline] sh\n+ docker version\nClient: Docker Engine - Community\n Version:           20.10.5\n API version:       1.41\n Go version:        go1.13.15\n Git commit:        55c4c88\n Built:             Tue Mar  2 20:17:50 2021\n OS/Arch:           linux/amd64\n Context:           default\n Experimental:      true\n\nServer: Docker Engine - Community\n Engine:\n  Version:          20.10.5\n  API version:      1.41 (minimum version 1.12)\n  Go version:       go1.13.15\n  Git commit:       363e9a8\n  Built:            Tue Mar  2 20:15:47 2021\n  OS/Arch:          linux/amd64\n  Experimental:     false\n containerd:\n  Version:          1.4.4\n  GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e\n runc:\n  Version:          1.0.0-rc93\n  GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec\n docker-init:\n  Version:          0.19.0\n  GitCommit:        de40ad0\n[Pipeline] echo\n构建完成.\n[Pipeline] script\n[Pipeline] {\n[Pipeline] fileExists\n[Pipeline] }\n[Pipeline] // script\n[Pipeline] archiveArtifacts\nArchiving artifacts\nRecording fingerprints\n[Pipeline] }\n[Pipeline] // stage\n[Pipeline] stage\n[Pipeline] { (测试)\n[Pipeline] echo\n单元测试中...\n[Pipeline] echo\n单元测试完成.\n[Pipeline] writeFile\n[Pipeline] junit\nRecording test results\n[Checks API] No suitable checks publisher found.\n[Pipeline] }\n[Pipeline] // stage\n[Pipeline] stage\n[Pipeline] { (部署)\n[Pipeline] echo\n部署中...\n[Pipeline] echo\n部署完成\n[Pipeline] }\n[Pipeline] // stage\n[Pipeline] }\n[Pipeline] // node\n[Pipeline] End of Pipeline\nFinished: SUCCESS\n"` // 返回说明文字
}

type FailGetBuildConsoleOutput struct {
	Code int    `json:"code" example:"12003"`     // 业务响应状态码
	Msg  string `json:"message" example:"获取信息失败"` // 提示信息
	Data string `json:"data" example:""`          // 返回错误信息
}

type SuccessGetStage struct {
	Code int                           `json:"code" example:"200"`     // 业务响应状态码
	Msg  string                        `json:"message" example:"请求成功"` // 提示信息
	Data models.BuildStageInfoResponse `json:"data" `                  // 返回错误信息
}

type FailGetStage struct {
	Code int    `json:"code" example:"12004"`       // 业务响应状态码
	Msg  string `json:"message" example:"获取构建步骤失败"` // 提示信息
	Data string `json:"data" example:""`            // 返回错误信息
}

type SuccessGetStageSimple struct {
	Code int                       `json:"code" example:"200"`     // 业务响应状态码
	Msg  string                    `json:"message" example:"请求成功"` // 提示信息
	Data []models.BuildStageSimple `json:"data" `                  // 返回错误信息
}

type SuccessGetInputAction struct {
	Code int                  `json:"code" example:"200"`     // 业务响应状态码
	Msg  string               `json:"message" example:"请求成功"` // 提示信息
	Data api_type.InputAction `json:"data" example:""`        // 返回说明文字
}

type SuccessInputSubmit struct {
	Code int    `json:"code" example:"200"`     // 业务响应状态码
	Msg  string `json:"message" example:"请求成功"` // 提示信息
	Data string `json:"data" example:"确认成功"`    // 返回说明文字
}
